<?php 
namespace app\Index\controller;
use think\Controller;
use think\Request;
use app\index\model\Customer;
class Customerc extends Base
{
    public function account($key=null)
    {
        if(Request::instance()->isAjax()){
            // $key 由ajax传入，也可用通过input('get.key.uid')来取得，使用input获取时，必须保证key的名称与ajax提交的名称一致
            $uid = is_array($key) ? (isset($key['uid']) ? $key['uid'] : null) : input("post.uid");
            $page = input("get.page") ? input("get.page")  : 1;//页码
            $limit = input("get.limit") ? input("get.limit") : 5;//每页条数
            $customer = new Customer();
            $data = $customer -> search_customer($uid, $page, $limit);
            // layui数据表格要求返回数据code必须为0
            return json(array("status"=>1, "code"=>0, "count"=>$data['count'], "message"=>"查询成功！", "data"=>$data["data"]));
        }
        return json(array("status"=>0, "code"=>0, "message"=>"非法查询！","data"=>[]));    
    }

    public function account_flow($key=null)
    {
        if(Request::instance()->isAjax()){
            $uid = is_array($key) ? (isset($key['uid']) ? $key['uid'] : null) : input("post.uid");
            $customer = new Customer();
            $result = $customer -> account_flow($uid);
            return json(array("code"=>1,"data"=>$result["data"],"message"=>"查询成功"));
        }
        return json(array("status"=>0, "code"=>0, "message"=>"非法查询！","data"=>[]));
    }
    
    public function cash_list($key=null)
    {
        if(Request::instance()->isAjax()){
            // $key 由ajax传入，也可用通过input('get.key.uid')来取得，使用input获取时，必须保证key的名称与ajax提交的名称一致
            $page = input("request.page") ? input("request.page")  : 1;//页码
            $limit = input("request.limit") ? input("request.limit") : 5;//每页条数
            $customer = new Customer();
            $data = $customer -> cash_list($page, $limit);
            // layui数据表格要求返回数据code必须为0
            return json(array("status"=>1, "code"=>0, "count"=>$data['count'], "message"=>"查询成功！", "data"=>$data["data"]));
        }
        return json(array("status"=>0, "code"=>0, "message"=>"非法查询！","data"=>[]));    
    }

    //数据接口
    //recharge
    public function recharge($key=null)
    {
        if(Request::instance()->isAjax()){
            $uid = is_array($key) ? (isset($key['uid']) ? $key['uid'] : null) : input("post.uid");
            $page = input("request.page") ? input("request.page")  : 1;//页码
            $limit = input("request.limit") ? input("request.limit") : 5;//每页条数
            $customer = new Customer();
            $checked = $customer -> check_customer($uid);
            if ($checked["status"] != 0){
                $data = $customer -> recharge($uid, $page, $limit);
            }
            // layui数据表格要求返回数据code必须为0
            return json(array("status"=>1, "code"=>0, "count"=>$data['count'], "message"=>"查询成功！", "data"=>$data["data"]));
        }
        return json(array("status"=>0, "code"=>0, "message"=>"非法查询！","data"=>[]));
    }
    public function recharge_group_list($key=null)
    {
        if(Request::instance()->isAjax()){
            $uid = is_array($key) ? (isset($key['cardnum']) ? $key['cardnum'] : null) : input("post.cardnum");
            $platform = input("request.platform") ? input("request.platform")  : "";
            $page = input("request.page") ? input("request.page")  : 1;//页码
            $limit = input("request.limit") ? input("request.limit") : 5;//每页条数
            $customer = new Customer();
            $data = $customer -> recharge_group_list($uid, $platform);
            return json(array("status"=>1, "code"=>0, "count"=>$data['count'], "message"=>"查询成功！", "data"=>$data["data"]));
        }
    }
    //consumption
    public function consumption($key=null)
    {
        if(Request::instance()->isAjax()){
            $uid = is_array($key) ? (isset($key['uid']) ? $key['uid'] : null) : input("post.uid");
            $page = input("request.page") ? input("request.page")  : 1;//页码
            $limit = input("request.limit") ? input("request.limit") : 5;//每页条数
            $customer = new Customer();
            $checked = $customer -> check_customer($uid);
            if ($checked["status"] != 0){
                $data = $customer -> consumption($uid, $page, $limit);
            }
            
            
            // layui数据表格要求返回数据code必须为0
            return json(array("status"=>1, "code"=>0, "count"=>$data['count'], "message"=>"查询成功！", "data"=>$data["data"]));
        }
        return json(array("status"=>0, "code"=>0, "message"=>"非法查询！","data"=>[]));
    }
    //consumption
    public function cash($key=null)
    {
        if(Request::instance()->isAjax()){
            $uid = is_array($key) ? (isset($key['uid']) ? $key['uid'] : null) : input("post.uid");
            $page = input("request.page") ? input("request.page")  : 1;//页码
            $limit = input("request.limit") ? input("request.limit") : 5;//每页条数
            $customer = new Customer();
            $checked = $customer -> check_customer($uid);
            if ($checked["status"] != 0){
                $data = $customer -> cash($uid, $page, $limit);
            }
            
            
            // layui数据表格要求返回数据code必须为0
            return json(array("status"=>1, "code"=>0, "count"=>$data['count'], "message"=>"查询成功！", "data"=>$data["data"]));
        }
        return json(array("status"=>0, "code"=>0, "message"=>"非法查询！","data"=>[]));
    }
    //consumption
    public function scores_consumption($key=null)
    {
        if(Request::instance()->isAjax()){
            $uid = is_array($key) ? (isset($key['uid']) ? $key['uid'] : null) : input("post.uid");
            $page = input("request.page") ? input("request.page")  : 1;//页码
            $limit = input("request.limit") ? input("request.limit") : 5;//每页条数
            $customer = new Customer();
            $checked = $customer -> check_customer($uid);
            if ($checked["status"] != 0){
                $data = $customer -> scores_consumption($uid, $page, $limit);
            }
            
            
            // layui数据表格要求返回数据code必须为0
            return json(array("status"=>1, "code"=>0, "count"=>$data['count'], "message"=>"查询成功！", "data"=>$data["data"]));
        }
        return json(array("status"=>0, "code"=>0, "message"=>"非法查询！","data"=>[]));
    }
    //consumption
    public function scores_simple($key=null)
    {
        if(Request::instance()->isAjax()){
            $uid = is_array($key) ? (isset($key['uid']) ? $key['uid'] : null) : input("post.uid");
            $page = input("request.page") ? input("request.page")  : 1;//页码
            $limit = input("request.limit") ? input("request.limit") : 5;//每页条数
            $customer = new Customer();
            $checked = $customer -> check_customer($uid);
            if ($checked["status"] != 0){
                $data = $customer -> scores_simple($uid, $page, $limit);
            }
            
            
            // layui数据表格要求返回数据code必须为0
            return json(array("status"=>1, "code"=>0, "count"=>$data['count'], "message"=>"查询成功！", "data"=>$data["data"]));
        }
        return json(array("status"=>0, "code"=>0, "message"=>"非法查询！","data"=>[]));
    }
}